<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta http-equiv="Content-Language" content="UTF-8">
    </head>
    <body>
<?php
$link = new Mysqli('192.168.1.108', 'root', '123456', 'test_fscsddt');
$link->query("SET NAMES 'utf8'");
$result = $link->query("select distinct substring(type, 1, 2) as `id`, `INDUSTRYTYPE1` as `name` from ritu_industry");
while ($row = $result->fetch_assoc()) {
    $sql = "insert into `foundation_ritu_industry` (code, name, parent_code) values ('{$row['id']}000000','{$row['name']}','00000000')";
    $link->query($sql);
};

$result = $link->query("select distinct substring(type, 1, 4) as `id`, `INDUSTRYTYPE2` as `name` from ritu_industry");
while ($row = $result->fetch_assoc()) {
    $parentCode = substr($row['id'], 0, 2);
    $sql = "insert into `foundation_ritu_industry` (code, name, parent_code) values ('{$row['id']}0000','{$row['name']}','{$parentCode}000000')";
    $link->query($sql);
};

$result = $link->query("select distinct substring(type, 1, 6) as `id`, `INDUSTRYTYPE3` as `name` from ritu_industry");
while ($row = $result->fetch_assoc()) {
    $parentCode = substr($row['id'], 0, 4);
    $sql = "insert into `foundation_ritu_industry` (code, name, parent_code) values ('{$row['id']}00','{$row['name']}','{$parentCode}0000')";
    $link->query($sql);
};

$result = $link->query("select distinct type as `id`, `INDUSTRYTYPE4` as `name` from ritu_industry");
while ($row = $result->fetch_assoc()) {
    if(substr($row['id'], -2) == '00'){
        continue;
    }
    $parentCode = substr($row['id'], 0, 6);
    $sql = "insert into `foundation_ritu_industry` (code, name, parent_code) values ('{$row['id']}','{$row['name']}','{$parentCode}00')";
    echo $sql.'<br/>';
    $link->query($sql);
};
?>
    </body>
</html>